#!/bin/sh
#
# sa3250_ch_guid
#

GUID="$1"
MODE="$2"
CHANNEL="$3"

STB_ON=2

NODE=$(plugreport 2>/dev/null | awk '/'$GUID'/ {print $2}' - )

STATUS=$(/usr/local/bin/sa3250cmd -n $NODE status ; echo $?)

# the status check is immmediate but powering on provides a 1 second guard time
# so only power on if the STB is actually off 
if [ $STATUS -ne $STB_ON ]
then
    /usr/local/bin/sa3250cmd -n $NODE on
fi

/usr/local/bin/mythchanger -g $GUID -f $MODE -c $CHANNEL
